;(function($){
    "use strict";
    $.fn.banner = function(ops = {}){
        let{items,btn=true,list=true,autoplay=true,keeptime=3000,movetime=200,index=0 } = ops;
        let iprev 
        if(btn){
            $("<button>").text("<").appendTo(this).css({
                position:"absolute",
                left:70,
                top:0,
                bottom:0,
                margin:"auto 0",
                width:60,
                height:80,
                fontSize:50,
                fontWeight:800,
                background:"rgba(200,200,200,0.8)",
                opacity:0.5,
                color:"black",
            }).click(function(){
                if(index === 0){
                    index = items.length-1;
                    iprev = 0;
                }else{
                    index--;
                    iprev = index+1;
                }
                move(iprev,index,1);
            });
            $("<button>").text(">").appendTo(this).css({
                position:"absolute",
                right:70,
                top:0,
                bottom:0,
                margin:"auto 0",
                width:60,
                height:80,
                fontSize:50,
                fontWeight:800,
                background:"rgba(200,200,200,0.8)",
                opacity:0.5,
                color:"black",
            }).click(rightClick)
        };
        
        if(list){
            let str = "";
            $.each(items,function(index,val){
                str +=`<li></li>`;
            })
            $("<ul class='list1'>").appendTo(this).html(str).css({
                position:"absolute",
                left:0,
                bottom:20,
                right:0,
                width:200,
                height:5,
                margin:"0 auto",
                listStyle:"none",
            }).children("li").css({
                height:"100%",
                width:30,
                margin:"0 5px",
                float:"left",
                background:"rgba(0,0,0,0.4)",
            }).eq(index).css({
                background:"white",
            });


            $(".list1").find("li").mouseenter(function(){
                if($(this).index()>index){
                    move(index,$(this).index(),-1);
                }
                if($(this).index()<index){
                    move(index,$(this).index(),1);
                }
                index = $(this).index();
            });
        };
        //自动播放
        if(autoplay){
             
              let t = setInterval(() => {
                rightClick();
            }, keeptime);
            this.hover(function(){
                clearInterval(t);
            },function(){
                t = setInterval(() => {
                    rightClick();
                }, keeptime);
            })

        };

        function rightClick(){
            if(index === items.length-1){
                index = 0;
                iprev = items.length-1;
            }else{
            index++;
            iprev = index-1;
            }
            move(iprev,index,-1);
        }

        function move(iprev, index,direct){
            items.eq(iprev).css({
                left:"-15%"
            }).stop().animate({
                left:items.eq(0).width()*direct
            },movetime);
            items.eq(index).css({
                left:-items.eq(0).width()*direct
            }).stop().animate({
                left:"-15%"
            },movetime)
            if(!list) return;
            setActive($(".list1").children("li"),index)
        };

        function setActive(ali,index){
            ali.eq(index).css({
                background:"white",
                opacity:0.6,
            }).siblings().css({
                background:"rgba(0,0,0,0.4)",
            })
        }


    }





})(jQuery);//$符私有化